<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class Banner extends Model{
	
	protected $table = 'house_banner';
	protected $pk = 'b_id';
	
	
	public function message()
    {
        return $this->belongsTo('message');
    }
    public function add(){
		$photo = $this->upload('photo');
		$data=[
				'b_name'=>input("param.b_name"),
				'b_status'=>input("param.b_status"),
				'photo'=>$photo
			];
			
			//halt($data);
		$ban = new Banner();
		$result = $ban->save($data);
		return $result;
	}
	public function upload($fileName){
		// 获取表单上传文件 例如上传了001.jpg
		$file = request()->file($fileName);
		// 当前目录指的是入口文件（index.php)所在的目录
		$info = $file->move( './uploads');
		return $info->getSaveName();
	}
	public function acs($id){
	
	$index=self::where('b_id',$id)->find();
	print_r($index);
	die();
	return $index;
	}
	public function up1(){
		$aa=[
			'b_status'=>input('param.b_status'),
			'b_name'=>input('param.b_name'),
			];
		//halt($aa);die();
		$ca=new Banner();
		$query=$ca->where('b_id',input('param.b_id'))->update($aa);
		return $query;
		
	}
	public function up1xiu($file){
		$info = $file->move('./uploads');
		$newname=$info->getSaveName();
		//echo $newname;die();
//		echo(input('param.n_id'));
//		die;
		$ca=new Banner();
		$query = $ca->save([
		  'b_status'=>input('param.b_status'),
			'b_name'=>input('param.b_name'),
			'photo'=>$newname
		   
		],['b_id'=>input('param.b_id')]);
		
		
//		$aa=[
//			'n_address'=>input('param.n_address'),
//			'n_name'=>input('param.n_name'),
//			'photo'=>$newname
//			];
		
		//$aa['photo']=$newname;
		//halt($query);die();
		
		//$query=$ca->where('n_id',input('param.n_id'))->update($aa);
		return $query;
		
	}

}
?>